// JavaScript Document
// JavaScript Document
$(function(){
	showQrcode();
});

//显示下载产品二维码图片
function showQrcode() {
	for(var i =1 ; i <= $("#pageSize").val(); i++) {
		$("#yad"+i).hover(function(){
			$(this).find('div').show();
		},function(){
			$(this).find('div').hide();
		});
		/*$("#yap"+i).hover(function(){
			$(this).find('div').show();	
		},function(){
			$(this).find('div').hide();
		});*/
	}
}


//客户端下载分页查询
function phoneReload(page) {
	var data_param = {
		downloadId: $("#downloadId").val(),
		page : page
	};
	$.ajax({
		type:"POST",
		url:"/download/ajaxPage",
		data:data_param,
		async:false,
		dataType:"json",
		success:function(data){
			$('#page').val(data.page);
			$('#pageCount').val(data.pageCount);
			
			//手机客户端下载产品查询
			var phone = '';
			$("#phone").empty();
			var goodsDownloadList = data.goodsDownloadList;
			for(var i=0;i<goodsDownloadList.length;i++){
				var gd = goodsDownloadList[i];
				phone += '<div class="phodown_mok cle">';
				phone += '<div class="img_con"><img src="'+gd.imageUrl+'" width="100px" height="100px"></div>';
				phone += '<div class="text_con">';
				phone += '<h3>'+gd.goodsDownloadName+'</h3>';
				phone += '<p>'+gd.goodsDownloadDescribe+'</p>';
				phone += '<div class="btn_con cle">';
	            /*if(gd.isAndroid == 0){
	            	phone += '<div class="android">';
					phone += '<a href="#" class="btn"><i class="icon"></i><span>安卓版</span></a>';
					phone += '<a href="#" class="ewm" id="yad'+(i + 1)+'"><img src="'+gd.androidImageUrl+'" width="16" height="16" class="small"/><div class="tc_ewm" id="ewmad'+(i + 1)+'" style="display: none;"><img src="'+gd.androidImageUrl+'" width="160" height="160"/></div></a>';
					phone += '</div>';
	            }
				if(gd.isIos == 0 ){
	            	phone += '<div class="apple">';
	        		phone += '<a href="#" class="btn"><i class="icon"></i><span>IOS版</span></a>';
	        		phone += '<a href="#" class="ewm" id="yap'+(i + 1)+'"><img src="'+gd.iosImageUrl+'" width="16" height="16" class="small"/><div class="tc_ewm" id="ewmap'+(i + 1)+'" style="display:none;"><img src="'+gd.iosImageUrl+'" width="160" height="160"/></div></a>';
	        		phone += '</div>';
				}*/
				if(gd.isAndroid == 0 || gd.isAndroid == 0){
					phone += '<div class="phone">';
					phone += '<a href="javascript:dialog(\''+gd.androidImageUrl+'\',\''+gd.iosImageUrl+'\',\''+gd.goodsDownloadName+'\',\''+gd.goodsDownloadDescribe+'\',\''+gd.imageUrl+'\',\''+gd.slogan+'\',\''+gd.adapter+'\')" class="btn"><i class="icon"></i><span>手机版</span></a>';
					phone += '<a href="#" class="ewm" id="yad'+(i + 1)+'">';
					if(gd.isAndroid == 0) {
						phone += '<img src="'+gd.androidImageUrl+'" width="16" height="16" class="small"/><div class="tc_ewm" id="ewmad'+(i + 1)+'" style="display: none;"><img src="'+gd.androidImageUrl+'" width="160" height="160"/></div>';
					}else {
						phone += '<img src="'+gd.iosImageUrl+'" width="16" height="16" class="small"/><div class="tc_ewm" id="ewmad'+(i + 1)+'" style="display:none;"><img src="'+gd.iosImageUrl+'" width="160" height="160"/></div>';
					}
					phone += '</a></div>';
				}
	            if(gd.isPc == 0 ){
	            	phone += '<div class="pc">';
	            	phone += '<a href="'+gd.pcUrl+'" class="btn"><i class="icon"></i><span>电脑版</span></a>';
	            	phone += '</div>';
	            }
	            if(gd.isInk == 0 ){
	            	phone += '<div class="pc">';
	            	phone += '<a href="'+gd.inkUrl+'" class="btn" style="width:100px;background:#FE6262;border-color:#FE6262;margin-left:30px;"><i class="icon"></i><span>桌面快捷式</span></a>';
	            	phone += '</div>';
	            }
            	phone += '</div>';
            	phone += '</div>';
            	phone += '</div>';
			}
      
			/*$.each(data.dpVos,function(index,dpv){
				if(data.dpVos.length > 0) {
					phone += '<div class="phodown_mok cle">'+
							 '<div class="img_con"><img src="'+dpv.product.productImg+'" width="100px" height="100px"></div>'+
						     '<div class="text_con">'+
						     '<h3>'+dpv.product.productName+'</h3>'+
						     '<p>'+dpv.product.productSpecialtyBrief+'</p>'+
						     '<div class="btn_con cle">';
					
					$.each(dpv.pdv,function(index1,pdv){
						if(pdv.downloadWayId == 1) {
							phone += '<div class="android">';
						}else if(pdv.downloadWayId == 2){
							phone += '<div class="apple">';
						}else {
							phone += '<div class="pc">';
						}
						
						if(pdv.downloadWayId == 4) {
							phone += '<a href="'+pdv.downloadUrl+'" class="btn" style="width:100px;background:#FE6262;border-color:#FE6262;margin-left:30px;"><i class="icon"></i><span>'+pdv.downloadWayName+'</span></a>';
						}else {
							phone += '<a href="'+pdv.downloadUrl+'" class="btn"><i class="icon"></i><span>'+pdv.downloadWayName+'</span></a>';
						}
						if(pdv.downloadWayId == 1) {
							phone += '<a href="#" class="ewm" id="yad'+ (index + 1) +'"><img src="'+pdv.productDownloadQrcode+'" width="16" height="16" class="small"/><div class="tc_ewm" id="ewmad'+ (index + 1) +'" style="display: none;"><img src="'+pdv.productDownloadQrcode+'" width="160" height="160"/></div></a>';
						}else if(pdv.downloadWayId == 2){
							phone += '<a href="#" class="ewm" id="yap'+ (index + 1) +'"><img src="'+pdv.productDownloadQrcode+'" width="16" height="16" class="small"/><div class="tc_ewm" id="ewmap'+ (index + 1) +'" style="display:none;"><img src="'+pdv.productDownloadQrcode+'" width="160" height="160"/></div></a>';
						}
						phone += '</div>';
					})
					phone += '</div></div></div>';
				}
				
			})*/
			phone +='<div class="page mt20" align="center">共'+data.totalRows+'条记录 '+data.page+'/'+data.pageCount+'页&nbsp;'+
					'<a href="javascript:phoneReload(1)">&nbsp;首页</a> <a onclick="javascript:ajaxPageUp('+data.page+')">上一页</a>&nbsp;'+
					'<a onclick="javascript:ajaxPageDown('+data.page+');">&nbsp;下一页</a>&nbsp;'+
					'<a href="javascript:phoneReload('+data.pageCount+')" >尾页</a>&nbsp;&nbsp;第&nbsp;&nbsp;'+
					'<select onchange="ajax2Page()" id="currPage">';
			for(var i = 1; i <= data.pageCount; i++) {
				phone += '<option value="'+i+'" ';
				if(data.page == i) {
					phone += 'selected="selected"';
				}
				phone += '>'+i+'</option>';
			}
			phone += '</select>&nbsp;页</div>';		
			$("#phone").append(phone);
			
		}
	})
	
	showQrcode();
}

function ajax2Page() {
	phoneReload($('#currPage').val());
}

//向上翻页
function ajaxPageUp(page) {
	if(page == 1) {
		BSTYUN.dialog.warn("已经是第一页");
		return;
	}else {
		var num = parseInt(page) - 1;
		phoneReload(num);
	}
}

//向下翻页
function ajaxPageDown(page) {
	if(page == $("#pageCount").val()) {
		BSTYUN.dialog.warn("已经是最后一页");
		return;
	}else {
		var num = parseInt(page) + 1;
		phoneReload(num);
	}
}

/*打开弹出框（手机端扫码下载）*/
function dialog(androidImageUrl,iosImageUrl,goodsDownloadName,goodsDownloadDescribe,imageUrl,slogan,adapter) {
	var qrcodeUrl = androidImageUrl;
	if(androidImageUrl == null || androidImageUrl == '') {
		qrcodeUrl = iosImageUrl;
	}
	var html = '<div class="APP-appcenter-wrap">' +
	           '<div class="APP-appcenter-mask"></div>' + 
	           '<div class="APP-appcenter-dialog"><a href="#" class="APP-appcenter-bClose" ></a>' +
	           '<div class="APP-appcenter-msgBoxIntro">' + 
	           '<div class="APP-appcenter-msgBoxIntro-header"><img src="'+imageUrl+'" alt="'+goodsDownloadName+'" width="75" height="75" class="APP-appcenter-msgBoxIntro-logo" />' +
	           '<h2 class="APP-appcenter-msgBoxIntro-name">'+goodsDownloadName+'</h2>' + 
	           '<div class="APP-appcenter-msgBoxIntro-info">' + 
	           '<span><b>口号：'+slogan+'</b></span></div>' + 
	          /* '<div class="APP-appcenter-btnOpt"> <a href="#" class="APP-appcenter-btn-addNow" >请扫左下角的二维码进行下载</a></div>' +*/
	           '</div>' + 
	           '<div class="APP-appcenter-msgBoxIntro-cont">' +
	           '<div class="APP-center-msgBoxIntro-picBox">' + 
	           '<ul class="APP-center-msgBoxIntro-piclist"><li class="App-center-msgBoxIntro-piclistItem">' +
	           '<img src="'+qrcodeUrl+'" alt="'+goodsDownloadName+'" height="200" /><br /><b>扫一扫，下载到手机了解更多</b></li></ul>' + 
	           '</div>' + 
	           '<div class="APP-appcenter-msgBoxIntro-word nui-scroll">' +
	           '<b>产品描述：</b><br />' +goodsDownloadDescribe+ '<br />' +
	           '<b>适用场景：</b><br />' + adapter + 
	           '</div></div></div></div>';
	
	/*打开弹出框*/
	BSTYUN.dialog.creat({
		  id:'appload',
		  content:html
		  });
}
